function Agg=Aggregation(PP,SS,QW_fzo,DistPolicy,UnitTrMat)

% DistPolicy_V=   SS.DistPolicy.V;
% DistPolicy_Vhat=SS.DistPolicy.Vhat;
% QW_fzo      =   SS.Dist_fzo.QW_fzo;
% DistPolicy    =   SS.DistPolicy;
% UnitTrMat       =   SS.TrProb.UnitTrMat;
%% Preliminaries
QW          =   UnitTrMat.ReEval*QW_fzo;
QW_V        =   (1-PP.XI)*QW;
QW_Vhat     =   PP.XI*QW;

f           =   SS.DistApp.fzo.State(:,1);
ID          =   SS.DistApp.fzo.State(:,2);
N_State     =   size(ID,1);

ID_FI       =   SS.FunApp.ExoState.State(ID,2);
ID_RI       =   SS.FunApp.ExoState.State(ID,3);

FI          =   PP.ExoState.Idio_FI.Node(ID_FI);
RI          =   PP.ExoState.Idio_RI.Node(ID_RI);

Mid_f       =   max(SS.DistApp.fzo.UnitNode{1}(cumsum(SS.Dist_fzo.Marginal_fzo.f)<0.5));

Ind         =   struct();

Ind.dom     =   FI==0;
Ind.ext     =   ~Ind.dom;

Ind.N       =   RI==0;
Ind.H       =   ~Ind.N;

Ind.rich    =   f>Mid_f;
Ind.poor    =   f<=Mid_f;

GroupList   =   {{'dom'},{'ext'},{'N'},{'H'},{'rich'},{'poor'}, ...
                 {'dom','N'},{'dom','H'},{'ext','N'},{'ext','H'}, ...
                 {'dom','rich'},{'dom','poor'},{'ext','rich'},{'ext','poor'}, ...
                 {'N','rich'},{'N','poor'},{'H','rich'},{'H','poor'}};
%% Aggregation
DistPolicy.V.f= f;
DistPolicy.Vhat.f=f;
% Weighted Policies
AggVarList  =   {'f','c','l','b','b_dom','b_ext','bp_dom','bp_ext',...
                 'fc','fp','zl','UI'};
for ii=1:length(AggVarList)
    vv              =   AggVarList{ii};
    QWQQ.V.(vv)     =   DistPolicy.V.(vv).*QW_V;
    QWQQ.Vhat.(vv)  =   DistPolicy.Vhat.(vv).*QW_Vhat;
end

% Aggregated Policies
Tot         =   struct();
Avg         =   struct();
Prob        =   struct();
for ii=1:length(GroupList)
    TempGroup   =   GroupList{ii};
    TempLabel   =   strjoin(TempGroup,'_');
    for jj=1:length(TempGroup)
        if jj==1
            TempInd     =   Ind.(TempGroup{jj});
        else
            TempInd     =   TempInd & Ind.(TempGroup{jj});
        end
    end
    Prob.(TempLabel) ...
                =   ( sum(QW_V(TempInd))+sum(QW_Vhat(TempInd)) );
    for jj=1:length(AggVarList)
        vv      =   AggVarList{jj};
        Tot.(vv).(TempLabel) ...
                =   sum(QWQQ.V.(vv)(TempInd))+sum(QWQQ.Vhat.(vv)(TempInd));
        Avg.(vv).(TempLabel) ...
                =   Tot.(vv).(TempLabel)/Prob.(TempLabel);
    end
end

C           =   Tot.c.dom+Tot.c.ext;

% Labor Supply
L_dom       =   Tot.zl.dom;
L_ext       =   Tot.zl.ext;

L_N         =   Tot.zl.N;
L_H         =   Tot.zl.H;

% Total Saving
F_dom       =   Tot.f.dom;
F_ext       =   Tot.f.ext;
Fp_dom      =   Tot.fp.dom;
Fp_ext      =   Tot.fp.ext;

% Total holding of bond
B_dom       =   Tot.b_dom.dom+Tot.b_dom.ext;
B_ext       =   Tot.b_ext.dom+Tot.b_ext.ext;
Bp_dom      =   Tot.bp_dom.dom+Tot.bp_dom.ext;
Bp_ext      =   Tot.bp_ext.dom+Tot.bp_ext.ext;

% Total Financial Service Cost
FC          =   Tot.fc.dom+Tot.fc.ext;

% Total UI Required
UI          =   Tot.UI.dom+Tot.UI.ext;

% Dispersion of Consumption Deviation
QQ_C_SS     =   [SS.DistPolicy.V.c;SS.DistPolicy.Vhat.c];
QQ_C        =   [DistPolicy.V.c;DistPolicy.Vhat.c];
TempQW      =   [QW_V;QW_Vhat];
Dev_C       =   log(QQ_C)-log(QQ_C_SS);
TempQW_W_SS =   QQ_C_SS.*TempQW;
TempQW_W_SS =   TempQW_W_SS/sum(TempQW_W_SS);
[Dev_C_Var,Dev_C_Mean,~] ...
            =   DistApp_QW_QW2Moment(TempQW_W_SS,Dev_C,[2]);
        
C_Dispersion=   [sqrt(Dev_C_Var);Dev_C_Mean];

Agg         =   struct('Tot',Tot,'Avg',Avg,'Prob',Prob, ...
                       'C',C,'L_dom',L_dom,'L_ext',L_ext,'L_N',L_N,'L_H',L_H, ...
                       'F_dom',F_dom,'F_ext',F_ext,'Fp_dom',Fp_dom,'Fp_ext',Fp_ext,...
                       'B_dom',B_dom,'Bp_dom',Bp_dom,'B_ext',B_ext,'Bp_ext',Bp_ext,...
                       'FC',FC,'UI',UI,'C_Dispersion',C_Dispersion);